<template>
    <div class="app-container">
       <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="90px">
          <el-form-item label="用户ID：" prop="keyword">
             <el-input
                v-model="queryParams.keyword"
                placeholder="请输入"
                clearable
                style="width: 240px"
                @keyup.enter="handleQuery"
             />
          </el-form-item>
          <el-form-item label="创建时间:" prop="timeRange">
            <el-date-picker
                v-model="queryParams.timeRange"
                type="datetimerange"
                range-separator=""
                style="width: 260px"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="YYYY-MM-DD HH:mm:ss"
                value-format="x"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
             <el-button icon="Refresh" @click="resetQuery">重置</el-button>
             <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
          </el-form-item>
       </el-form>
       <!-- 表格数据 -->
       <el-table v-loading="loading" :data="roleList">
          <el-table-column label="" prop="id" width="100" />
          <el-table-column label="用户ID" prop="roleName"  width="100" />
          <el-table-column label="用户昵称" prop="roleSort" width="100" />
          <el-table-column label="系统型号" prop="roleKey" :show-overflow-tooltip="true" />
          <el-table-column label="发送平台" prop="roleKey"  />
          <el-table-column label="版本号" prop="roleSort" />
          <el-table-column label="创建时间" prop="roleSort" >
            <template #default="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="ex" prop="roleSort" />
          <el-table-column label="" align="center" class-name="small-padding fixed-width">
             <template #default="scope">
                <el-button link type="primary" @click="handleDetail(scope.row)">详情</el-button>
             </template>
          </el-table-column>
       </el-table>
 
       <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="pageObj.pageNumber"
          v-model:limit="pageObj.showNumber"
          @pagination="getList"
       />
        <el-drawer size="20%" :title="title" v-model="openDrawer" direction="rtl" :before-close="handleClose" destroy-on-close>
          <el-form ref="roleRef" :model="form" :rules="rules" label-width="0px">
             <el-form-item label="" prop="roleName" v-show="single">
                <div class="radioContainer">
                    <el-radio v-model="radio1" label="1">普通群员</el-radio>
                    <el-radio v-model="radio1" label="2">群管理员</el-radio>
                    <el-radio v-model="radio1" label="3">群主</el-radio>
                </div>
             </el-form-item>
          </el-form>
          <el-form ref="roleRef" :model="form" :rules="rules" label-width="0px">
             <el-form-item label="" prop="roleName" v-show="!single">
                <div class="radioContainer">
                    <el-radio v-model="radio2" label="1">10分钟</el-radio>
                    <el-radio v-model="radio2" label="2">1小时</el-radio>
                    <el-radio v-model="radio2" label="3">12小时</el-radio>
                    <el-radio v-model="radio2" label="4">1天</el-radio>
                </div>
             </el-form-item>
             <div  class="customTime" v-show="!single">自定义时长</div>
             <el-form-item label="" prop="timer" v-show="!single">
                <el-input v-model="form.timer" />
             </el-form-item>
          </el-form>
          <template #footer>
             <div class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
             </div>
          </template>
       </el-drawer>
    </div>
</template>
<script setup name="userMessage">
import { ref, reactive, onMounted, onBeforeUnmount } from 'vue'
import { getLogList } from "@/api/im/log";
import { start } from 'nprogress';
 const { proxy } = getCurrentInstance();
 const roleList = ref([]);
 const loading = ref(true);
 const showSearch = ref(true);
 const ids = ref([]);
 const single = ref(true);
 const multiple = ref(true);
 const total = ref(0);
 const title = ref("");
 const type = ref('add')
 const dateRange = ref([]);
 const open = ref(false);
 const options = [
    {value: 'single', label: '单聊'},
    {value: 'system', label: '系统通知'},
 ]
 const messageOptions = ref([])
 
 const data = reactive({
   form: {},
   queryParams: {
     keyword: undefined,
     timeRange:undefined,
   },
   pageObj:{
      pageNumber: 1,
      showNumber: 10
   },
   rules: {
     groupName: [{ required: true, message: "群组名称不能为空", trigger: "blur" }],
   },
 });
 
 const { queryParams, form, rules,pageObj } = toRefs(data);
  
 /** 查询角色列表 */
 function getList() {
   loading.value = true;
   const parmas = {
    pagination: pageObj.value,
    current: 1,
    pageSize: 10,
    keyword: queryParams.value.keyword,
    startTime: queryParams.value.timeRange? queryParams.value.timeRange[0]:undefined,
    endTime: queryParams.value.timeRange? queryParams.value.timeRange[1]:undefined
   }
   getLogList(parmas).then(response => {
     roleList.value = response.data.logsInfos;
     total.value = response.data.total;
     loading.value = false;
   });
 }
 
 /** 搜索按钮操作 */
 function handleQuery() {
   queryParams.value.pageNum = 1;
   getList();
 }
 
 /** 重置按钮操作 */
 function resetQuery() {
   dateRange.value = [];
   proxy.resetForm("queryRef");
   handleQuery();
 }
 getList();
</script>